package writer_;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author DCSGO
 * @version 1.0
 * BufferedWriter 向文件中写入字符
 */
public class BufferedWriter_ {
    public static void main(String[] args) throws IOException {
        String filePath = "C:\\Users\\Administrator\\Desktop\\Javacode\\java-learning-code\\chapter19\\src\\writer_\\a.txt";
        //是否以追加的方式写入数据 需要在 new 节点流时指定
        //BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath));//覆盖
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath, true));//追加

        bufferedWriter.write("你的名字");
        bufferedWriter.newLine();//插入一个与当前环境相关联的换行符
        bufferedWriter.write("你的名字");
        bufferedWriter.newLine();
        bufferedWriter.write("你的名字");
        bufferedWriter.newLine();

        //关闭外层流即可 底层会关闭其内部的节点流
        bufferedWriter.close();
        System.out.println("写入完成");
    }
}
